﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace ActionSystem.Core
{
    /// <summary>
    /// 浅拷贝接口
    /// </summary>
    public interface IShadowCopy
    {
        /// <summary>
        /// 浅拷贝
        /// </summary>
        /// <returns></returns>
        object Clone();
        /// <summary>
        /// 重置浅拷贝字段为默认值
        /// </summary>
        void ResetUnSharedFileds();
    }
    /// <summary>
    /// 浅拷贝工具
    /// </summary>
    public static class ShadowCopy
    {
        public static T Copy<T>(IShadowCopy raw) where T: class,IShadowCopy
        {
            if(raw==null)
            {
                return null;
            }
            object res = raw.Clone();
            (res as IShadowCopy)?.ResetUnSharedFileds();
            return res as T;
        }
    }

}


